package com.jewelry.web.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jewelry.common.util.Constants;
import com.jewelry.service.IConsumablesLogService;
import com.jewelry.service.IConsumablesService;
import com.jewelry.vo.ConsumablesLogVO;
import com.jewelry.vo.ConsumablesVO;

public class ConsumablesAction extends HttpAction {

	private static final long serialVersionUID = 8507800577558770349L;
	
	private static Logger logger = LoggerFactory.getLogger(ConsumablesAction.class);
	
	private IConsumablesService consumablesService;
	
	private IConsumablesLogService consumablesLogService;
	
	private int allConsumablesCount;
	
	private ConsumablesLogVO consumablesLog;
	
	public IConsumablesLogService getConsumablesLogService() {
		return consumablesLogService;
	}

	public void setConsumablesLogService(
			IConsumablesLogService consumablesLogService) {
		this.consumablesLogService = consumablesLogService;
	}

	public ConsumablesLogVO getConsumablesLog() {
		return consumablesLog;
	}

	public void setConsumablesLog(ConsumablesLogVO consumablesLog) {
		this.consumablesLog = consumablesLog;
	}

	private List<ConsumablesVO> consumablesList;
	
	private List<ConsumablesLogVO> consumablesLogList;

	public List<ConsumablesLogVO> getConsumablesLogList() {
		return consumablesLogList;
	}

	public void setConsumablesLogList(List<ConsumablesLogVO> consumablesLogList) {
		this.consumablesLogList = consumablesLogList;
	}

	public List<ConsumablesVO> getConsumablesList() {
		return consumablesList;
	}

	public void setConsumablesList(List<ConsumablesVO> consumablesList) {
		this.consumablesList = consumablesList;
	}

	public int getAllConsumablesCount() {
		return allConsumablesCount;
	}

	public void setAllConsumablesCount(int allConsumablesCount) {
		this.allConsumablesCount = allConsumablesCount;
	}

	public IConsumablesService getConsumablesService() {
		return consumablesService;
	}

	public void setConsumablesService(IConsumablesService consumablesService) {
		this.consumablesService = consumablesService;
	}
	
	//==============================================================
	
	public String consumablesAdminMain(){
		allConsumablesCount = consumablesService.getConsumablesCount();
		consumablesList = consumablesService.getConsumablesList();
		return SUCCESS;
	}
	
	public String queryConsumablesList(){
		if(logger.isDebugEnabled()){
			logger.debug("start queryConsumablesList ... ");
		}
		if(consumablesLog==null){
			consumablesLog = new ConsumablesLogVO();
		}
		consumablesList = consumablesService.getConsumablesList();
		consumablesLogList = consumablesLogService.getConsumablesLogByPage(consumablesLog);
		return SUCCESS;
	}
	
	public String addConsumablesLogPage(){
		consumablesList = consumablesService.getConsumablesList();
		return SUCCESS;
	}
	
	public String addingConsumablesLog(){
		consumablesList = consumablesService.getConsumablesList();
		try{
			consumablesLogService.addConsumablesLog(consumablesLog);
			message="保存成功！您可以继续添加...";
			consumablesLog = null;
		}catch(Exception e){
			logger.error("addConsumablesLog error!",e);
			message= Constants.SYSTEM_ERROR_MSG;
		}
		return SUCCESS;
	}

}
